<?php


class RoutineHelper extends AppHelper {

/******************************************************************************/

var $helpers = array('Html', 'Form');

/******************************************************************************/

function icon($icon_name, $options = array()) {
	return $this->Html->image('/libs/silk_icons/' . $icon_name . '.png', $options);
}

function flag($flag_name, $options = array()) {
	return $this->Html->image('/libs/flag_icons/' . $flag_name . '.png', $options);
}

/******************************************************************************/

function buttonSubmit($icon_name, $title, $htmlAttributes = array()) {
	$htmlAttributes['class'] = 'submit';
	$text = trim(implode(array_map(array($this, 'icon'), (array)$icon_name)) . ' ' . $title);
	return $this->Html->tag('button', $text, $htmlAttributes);
}

function buttonSubmitClose($icon_name, $title, $htmlAttributes = array()) {
	$htmlAttributes['class'] = 'submit submit_close';
	$text = trim(implode(array_map(array($this, 'icon'), (array)$icon_name)) . ' ' . $title);
	return $this->Html->tag('button', $text, $htmlAttributes);
}

function buttonSubmitClose2($icon_name, $title, $htmlAttributes = array()) {
	$htmlAttributes['class'] = 'submit submit_close_2';
	$text = trim(implode(array_map(array($this, 'icon'), (array)$icon_name)) . ' ' . $title);
	return $this->Html->tag('button', $text, $htmlAttributes);
}

function buttonUpload($icon_name, $title, $url = NULL, $htmlAttributes = array()) {
	if (isset($htmlAttributes['field_name'])) {
		$field_name = $htmlAttributes['field_name'];
		unset($htmlAttributes['field_name']);
	} else {
		$field_name = 'file';
	}
	$html = '<form action="' . $this->Html->url($url) . '" method="post" enctype="multipart/form-data">';
	$html .= '<input type="file" name="' . $field_name . '" />';
	$html .= $this->buttonSubmit($icon_name, $title);
	$html .= '</form>';
	return $html;
}

function button($icon_name, $title, $url = NULL, $htmlAttributes = array()) {
	if (isset($htmlAttributes['target'])) {
		$onclick = 'window.open(\'' . addslashes($this->Html->url($url)) . '\', \'' . addslashes($htmlAttributes['target']) . '\');';
		unset($htmlAttributes['target']);
	} else {
		$onclick = 'location.replace(\'' . addslashes($this->Html->url($url)) . '\');';
	}
	if (isset($htmlAttributes['confirm'])) {
		$onclick = 'if (confirm(\'' . addslashes($htmlAttributes['confirm']) . '\')) {' . $onclick . '}';
		unset($htmlAttributes['confirm']);
	}
	$onclick .= 'return false;';
	$htmlAttributes['onclick'] = $onclick;
	$text = trim(implode(array_map(array($this, 'icon'), (array)$icon_name)) . ' ' . $title);
	return $this->Html->tag('button', $text, $htmlAttributes);
}

/******************************************************************************/

}


?>